<?php
#-------------------------------------------------------------------------
# Module: Counters
# Version: 1.0, Jo Morg
# Method: Install
#-------------------------------------------------------------------------
# CMS - CMS Made Simple is (c) 2008 by Ted Kulp (wishy@cmsmadesimple.org)
# This project's homepage is: http://www.cmsmadesimple.org
# The module's homepage is: http://dev.cmsmadesimple.org/projects/skeleton/
#
#-------------------------------------------------------------------------

if(!is_object(@cmsms()))exit;

// mysql-specific, but ignored by other database
$taboptarray = array( 'mysql' => 'ENGINE=MyISAM' );

$dict = NewDataDictionary(cmsms()->GetDb());

// template stuff
$flds = "
    id I KEY AUTO,
    type_id I,
    title C(255),
    template X
";

$sqlarray = $dict->CreateTableSQL(cms_db_prefix() . "module_counters_templates",
        $flds, $taboptarray);
        
$dict->ExecuteSQLArray($sqlarray);

# triggers stuff

$flds = "
    id I KEY AUTO,
    type_id I,
    title C(255),
    template X
";
$sqlarray = $dict->CreateTableSQL(cms_db_prefix() . "module_counters_triggers",
        $flds, $taboptarray);

$dict->ExecuteSQLArray($sqlarray);

// table schema description
$flds = "
          cntr_id I KEY AUTO,
          name C(255),
          description C(255),
          explanation X,
          value I default 0,
          ceiling I default 0,
          product_id I,
          key1 I,
          key2 I,
          Key3 I,
          triggers_id  I
";
			
// create it. This should do error checking, but I'm a lazy sod.
$sqlarray = $dict->CreateTableSQL( cms_db_prefix() . "module_counters",
				   $flds, 
				   $taboptarray);
           
$dict->ExecuteSQLArray($sqlarray);

// create a permission
$this->CreatePermission('Use Counters', 'Use Counters');
$this->CreatePermission('Set Counters Prefs', 'Set Counters Prefs');

// create a preference
$this->SetPreference("allow_add", true);

// register an event that the Skeleton will issue. Other modules
// or user tags will be able to subscribe to this event, and trigger
// other actions when it gets called.
#$this->CreateEvent( 'OnSkeletonPreferenceChange' );
$this->CreateEvent( 'OnCounterCeilingReached' );

// put mention into the admin log
$this->Audit( 
              0, 
	            $this->Lang('friendlyname'), 
	            $this->Lang('installed', $this->GetVersion() ) 
            );

	      
?>
